<?php
namespace Admin\Controller;
use Think\Controller;

class PublicController extends Controller  {

    // 展示登录界面
    public function login(){
        if(IS_POST) { $this->loginPost();exit;}
        if(is_login()) $this->redirect('Index/index');

        $this->display();
    }

    // 处理登录
    public function loginPost(){
        $model = D('Admin');
        $data = $model->create($_POST,4);
        if(!$data) $this->error($model->getError());
        $admin = $model->login($data['username'],$data['password'],$data['remember']);
        if(!$admin){
            $this->error($model->getError());
        }else{
            $this->success('登录成功',U('Index/index'));
        }
    }

    // 退出登录
    public function logout(){
        session(null);
        cookie('adminToken',null);
        $this->redirect(__MODULE__);
    }




    // 输出验证码
    public function verify(){
        $config = array(
            'length'=>4,
            'fontSize'=>34,
            'useCurve'=>false,
            'useNoise'=>true,
            'imageW'=>'320px',
            'imageH'    =>  '80px',
            // 'fontttf' => '2.ttf',
            'codeSet' => '23456789ABCDEFGHJKLMNPQRSTUVWXYZ',
        );
        $verify = new \Think\Verify($config);
        $verify->entry(1);
    }
}